<template>
	<view class="content">
		
		<qiun-title-bar title="日记云图"/>
		<view class="charts-box">
		  <qiun-data-charts type="word" :chartData="data"/>
		</view>
		
		<view class="analyse" v-if="isShow">
			<view class="theme">{{analyse.theme}}</view>
			<view class="textA">
				{{analyse.analyse}}
			</view>
			<view class="textB">
				{{analyse.content}}
			</view>
			<view class="textC">
				{{analyse.suggest}}
			</view>
		</view>
		<view v-if="btnIsShow">
			<button type="primary" @click="sendEmail">获取分析报告</button>
		</view>
	</view>
</template>

<script>
	import {getWordCloud} from '@/api/sentiment.js';
	import {getWordCloudAnalyse,sendEmailAsToday} from '@/api/wordCloud.js';
	export default {
		data() {
			return {
				isShow:false,
				btnIsShow:false,
				data:{ "series": 
					[ 
						{ "name": "写个日记吧", "textSize": 25 },
						{ "name": "今天还没写日记哟", "textSize": 20 }, 
						{ "name": "今天过的怎样", "textSize": 20 },
						{ "name": "没事的", "textSize": 20 },
						{ "name": "相信自己", "textSize": 20 },
						{ "name": "不是噩梦", "textSize": 20 },
						{ "name": "抱抱", "textSize": 20 }, 
						{ "name": "你好呀", "textSize": 20 }, 
						{ "name": "你的日记", "textSize": 10 }, 
						{ "name": "你的日记", "textSize": 12 }, 
						{ "name": "你的日记", "textSize": 10 }, 
						{ "name": "你的日记", "textSize": 12 }, 
						{ "name": "你的日记", "textSize": 10 }, 
						{ "name": "你的日记", "textSize": 12 }, 
						{ "name": "你的日记", "textSize": 10 }, 
						{ "name": "你的日记", "textSize": 12 } ,
					] ,
					},
					analyse:{
						
					}

			};
		},
		methods:{
			getData(){
				
				getWordCloud({
					id:uni.getStorageSync("id"),
					token:uni.getStorageSync("authorization")
				}).then(res=>{
					console.log(res)
					if(res.data.data!=null){
						
						this.data = res.data.data
					}
				})
			},
			sendEmail(){
				uni.showLoading({
					title: '正在发送'
				});
				sendEmailAsToday({
					id:uni.getStorageSync("id"),
					token:uni.getStorageSync("authorization")
				}).then(res=>{
					console.log(res)
					if(res.data.code==200){
						uni.hideLoading();
						this.btnIsShow = false
					}else{
						uni.hideLoading();
					}
				})
			},
			getAnalyse(){
				getWordCloudAnalyse({
					id:uni.getStorageSync("id"),
					token:uni.getStorageSync("authorization")
				}).then(res=>{
					console.log(res)
					if(res.data.data!=null){
						
						this.analyse = res.data.data
						this.isShow = true
						this.btnIsShow = true
					}
				})
			}
		},
		created() {
			this.getData()
			
		},
		mounted() {
			this.getAnalyse()
		}
	}
</script>

<style lang="scss">
.content{
		button{
			width: 80%;
			margin-top: 2vh;
		}
		.analyse{
			background-color: $bg-gary;
			width: 70%;
			margin: auto;
			border-radius: 3vh;
			color: $font-blue;
			padding: 5vh;
			view{
				margin-top: 2vh;
			}
			.theme{
				font-size: 3vh;
				font-weight: bold;
				text-align: center;
			}
		}
}
</style>
